package com.haoji.upload.common.dto;

import com.haoji.upload.common.constant.ResponseEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @program: upload
 * @description:
 * @author: xiaolei
 * @create: 2021-04-16 16:12
 **/
@Data
@ApiModel(value = "WebResponse",description = "接口返回对象")
public class WebResponse<T> {

    @ApiModelProperty(value = "响应码，默认200")
    private String code = ResponseEnum.SUCCESS.getCode();

    @ApiModelProperty(value = "响应信息，默认''")
    private String message = ResponseEnum.SUCCESS.getMessage();

    @ApiModelProperty(value = "返回消息主体")
    private T body;

    public WebResponse() {
    }

    public WebResponse(String code, String message, T body) {
        this.code = code;
        this.message = message;
        this.body = body;
    }

    public WebResponse(ResponseEnum responseEnum, T body) {
        this.code = responseEnum.getCode();
        this.message = responseEnum.getMessage();
        this.body = body;
    }

    public WebResponse(T body) {
        this.code = ResponseEnum.SUCCESS.getCode();
        this.message = ResponseEnum.SUCCESS.getMessage();
        this.body = body;
    }

    public static <T> WebResponse<T> error(T body){
       return new WebResponse<>(ResponseEnum.ERROR,body);
    }

    public static <T> WebResponse<T> success(T body){
        return new WebResponse<>(ResponseEnum.SUCCESS,body);
    }

}
